package util;

import javabean.User;
import com.mysql.cj.jdbc.Driver;
import java.sql.*;

public class ConnectMysql {

    public boolean ConnectMysql(User users) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/db1?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "root";
        Driver driver = new Driver();
        DriverManager.registerDriver(driver);
        Connection conn = DriverManager.getConnection(url, user, password);
        String sql = "select * from user where name =";
        sql += " '" + users.getUsername() + "' and password = '";
        sql += users.getPassword() + "'";
        System.out.println(sql);
        Statement statement = conn.createStatement();
        ResultSet rows = statement.executeQuery(sql);
        boolean flag = false;
        while (rows.next()) {
            flag = true;
        }
        statement.close();
        conn.close();
        return flag;
    }

}
